package com.atguigu.hbse;

import com.google.common.hash.BloomFilter;
import com.google.common.hash.Funnels;

/**
 * Created by Smexy on 2023/4/17
 *
 *  guava: google java
 */
public class BloomFilterDemo
{
    public static void main(String[] args) {

        /*
            Funnel<T> funnel：  用于构造T类型的向量
            int expectedInsertions : 向量的长度，越长，准备率越高
            double falsePositiveProbability: 误判率:  准确率 = 1- falsePositiveProbability
         */
        BloomFilter<CharSequence> bloomFilter = BloomFilter.create(Funnels.stringFunnel(), 100, 0.01);

        String [] data = { "a","b","c","d","a","d","b"};

        for (int i = 0; i < data.length; i++) {

            //返回true，当前元素可能已经有，返回false，一定没有
            if (bloomFilter.mightContain(data[i])){
                System.out.println("index: "+i + "的元素: "+data[i] + "可能有...");
            }else {
                System.out.println("index: "+i + "的元素: "+data[i] + "一定不在");
            }
            if (!"b".equals(data[i])){
                bloomFilter.put(data[i]);
            }
        }

    }
}
